﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using FRL.DebtChased.Silverlight.Library.RichContentService;

namespace FRL.DebtChased.Silverlight.Library
{
    public class RefData
    {
        private static List<Country> _countries;
        public static List<Country> Countries
        {
            get
            {
                if (_countries == null)
                {
                    _countries = GetCountries();
                }
                return _countries;
            }
        }

        private static List<string> _counties;
        public static List<string> Counties
        {
            get
            {
                if (_counties == null)
                    _counties = GetCounties();
                return _counties;
            }
        }

        private static List<ContactAddressType> _addressTypes;
        public static List<ContactAddressType> AddressTypes
        {
            get
            {
                if (_addressTypes == null)
                {
                    _addressTypes = new List<ContactAddressType>();
                    _addressTypes.Add(new ContactAddressType((int)eContactAddressType.Default, "Default", "D", false));
                    _addressTypes.Add(new ContactAddressType((int)eContactAddressType.Memo, "Memo", "M", false));
                    _addressTypes.Add(new ContactAddressType((int)eContactAddressType.Additonal, "Additional", "A", false));
                    _addressTypes.Add(new ContactAddressType((int)eContactAddressType.DefaultForeign, "Default Foreign", "DF", true));
                    _addressTypes.Add(new ContactAddressType((int)eContactAddressType.MemoForeign, "Memo Foreign", "MF", true));
                    _addressTypes.Add(new ContactAddressType((int)eContactAddressType.AdditonalForeign, "Additional Foreign", "AF", true));
                }
                return _addressTypes;
            }
        }

        public static string GetAddressTypeCode(int addressType)
        {
            foreach (ContactAddressType type in AddressTypes)
                if (type.TypeId == addressType)
                    return type.Code;
            return string.Empty;
        }

        private static List<Country> GetCountries()
        {
            List<Country> countries = new List<Country>();

            countries.Add(new Country(1, "AF", "Afghanistan"));
            countries.Add(new Country(2, "AL", "Albania"));
            countries.Add(new Country(3, "DZ", "Algeria"));
            countries.Add(new Country(4, "AS", "American Samoa"));
            countries.Add(new Country(5, "AD", "Andorra"));
            countries.Add(new Country(6, "AO", "Angola"));
            countries.Add(new Country(7, "AI", "Anguilla"));
            countries.Add(new Country(8, "AQ", "Antarctica"));
            countries.Add(new Country(9, "AG", "Antigua and Barbuda"));
            countries.Add(new Country(10, "AR", "Argentina"));
            countries.Add(new Country(11, "AM", "Armenia"));
            countries.Add(new Country(12, "AW", "Aruba"));
            countries.Add(new Country(13, "AU", "Australia"));
            countries.Add(new Country(14, "AT", "Austria"));
            countries.Add(new Country(15, "AZ", "Azerbaijan"));
            countries.Add(new Country(16, "BS", "Bahamas"));
            countries.Add(new Country(17, "BH", "Bahrain"));
            countries.Add(new Country(18, "BD", "Bangladesh"));
            countries.Add(new Country(19, "BB", "Barbados"));
            countries.Add(new Country(20, "BY", "Belarus"));
            countries.Add(new Country(21, "BE", "Belgium"));
            countries.Add(new Country(22, "BZ", "Belize"));
            countries.Add(new Country(23, "BJ", "Benin"));
            countries.Add(new Country(24, "BM", "Bermuda"));
            countries.Add(new Country(25, "BT", "Bhutan"));
            countries.Add(new Country(26, "BO", "Bolivia"));
            countries.Add(new Country(27, "BA", "Bosnia and Herzegovina"));
            countries.Add(new Country(28, "BW", "Botswana"));
            countries.Add(new Country(29, "BV", "Bouvet Island"));
            countries.Add(new Country(30, "BR", "Brazil"));
            countries.Add(new Country(31, "IO", "British Indian Ocean Territory"));
            countries.Add(new Country(32, "VG", "British Virgin Islands"));
            countries.Add(new Country(33, "BN", "Brunei Darussalam"));
            countries.Add(new Country(34, "BG", "Bulgaria"));
            countries.Add(new Country(35, "BF", "Burkina Faso"));
            countries.Add(new Country(36, "BI", "Burundi"));
            countries.Add(new Country(37, "KH", "Cambodia"));
            countries.Add(new Country(38, "CM", "Cameroon"));
            countries.Add(new Country(39, "CA", "Canada"));
            countries.Add(new Country(40, "CV", "Cape Verde"));
            countries.Add(new Country(41, "KY", "Cayman Islands"));
            countries.Add(new Country(42, "CF", "Central African Republic"));
            countries.Add(new Country(43, "TD", "Chad"));
            countries.Add(new Country(44, "CL", "Chile"));
            countries.Add(new Country(45, "CN", "China"));
            countries.Add(new Country(46, "CX", "Christmas Island"));
            countries.Add(new Country(47, "CC", "Cocos"));
            countries.Add(new Country(48, "CO", "Colombia"));
            countries.Add(new Country(49, "KM", "Comoros"));
            countries.Add(new Country(50, "CG", "Congo"));
            countries.Add(new Country(51, "CK", "Cook Islands"));
            countries.Add(new Country(52, "CR", "Costa Rica"));
            countries.Add(new Country(53, "HR", "Croatia"));
            countries.Add(new Country(54, "CU", "Cuba"));
            countries.Add(new Country(55, "CY", "Cyprus"));
            countries.Add(new Country(56, "CZ", "Czech Republic"));
            countries.Add(new Country(57, "DK", "Denmark"));
            countries.Add(new Country(58, "DJ", "Djibouti"));
            countries.Add(new Country(59, "DM", "Dominica"));
            countries.Add(new Country(60, "DO", "Dominican Republic"));
            countries.Add(new Country(61, "TP", "East Timor"));
            countries.Add(new Country(62, "EC", "Ecuador"));
            countries.Add(new Country(63, "EG", "Egypt"));
            countries.Add(new Country(64, "SV", "El Salvador"));
            countries.Add(new Country(65, "GQ", "Equatorial Guinea"));
            countries.Add(new Country(66, "ER", "Eritrea"));
            countries.Add(new Country(67, "EE", "Estonia"));
            countries.Add(new Country(68, "ET", "Ethiopia"));
            countries.Add(new Country(69, "FK", "Falkland Islands"));
            countries.Add(new Country(70, "FO", "Faroe Islands"));
            countries.Add(new Country(71, "FJ", "Fiji"));
            countries.Add(new Country(72, "FI", "Finland"));
            countries.Add(new Country(73, "FR", "France"));
            countries.Add(new Country(74, "GF", "French Guiana"));
            countries.Add(new Country(75, "PF", "French Polynesia"));
            countries.Add(new Country(76, "TF", "French Southern Territories"));
            countries.Add(new Country(77, "GA", "Gabon"));
            countries.Add(new Country(78, "GM", "Gambia"));
            countries.Add(new Country(79, "GE", "Georgia"));
            countries.Add(new Country(80, "DE", "Germany"));
            countries.Add(new Country(81, "GH", "Ghana"));
            countries.Add(new Country(82, "GI", "Gibraltar"));
            countries.Add(new Country(83, "GR", "Greece"));
            countries.Add(new Country(84, "GL", "Greenland"));
            countries.Add(new Country(85, "GD", "Grenada"));
            countries.Add(new Country(86, "GP", "Guadeloupe"));
            countries.Add(new Country(87, "GU", "Guam"));
            countries.Add(new Country(88, "GT", "Guatemala"));
            countries.Add(new Country(89, "GN", "Guinea"));
            countries.Add(new Country(90, "GW", "Guinea-Bissau"));
            countries.Add(new Country(91, "GY", "Guyana"));
            countries.Add(new Country(92, "HT", "Haiti"));
            countries.Add(new Country(93, "HM", "Heard and McDonald Islands"));
            countries.Add(new Country(94, "HN", "Honduras"));
            countries.Add(new Country(95, "HK", "Hong Kong"));
            countries.Add(new Country(96, "HU", "Hungary"));
            countries.Add(new Country(97, "IS", "Iceland"));
            countries.Add(new Country(98, "IN", "India"));
            countries.Add(new Country(99, "ID", "Indonesia"));
            countries.Add(new Country(100, "IR", "Iran"));
            countries.Add(new Country(101, "IQ", "Iraq"));
            countries.Add(new Country(102, "IE", "Ireland"));
            countries.Add(new Country(103, "IL", "Israel"));
            countries.Add(new Country(104, "IT", "Italy"));
            countries.Add(new Country(105, "CI", "Ivory Coast"));
            countries.Add(new Country(106, "JM", "Jamaica"));
            countries.Add(new Country(107, "JP", "Japan"));
            countries.Add(new Country(108, "JO", "Jordan"));
            countries.Add(new Country(109, "KZ", "Kazakhstan"));
            countries.Add(new Country(110, "KE", "Kenya"));
            countries.Add(new Country(111, "KI", "Kiribati"));
            countries.Add(new Country(112, "KW", "Kuwait"));
            countries.Add(new Country(113, "KG", "Kyrgyzstan"));
            countries.Add(new Country(114, "LA", "Laos"));
            countries.Add(new Country(115, "LV", "Latvia"));
            countries.Add(new Country(116, "LB", "Lebanon"));
            countries.Add(new Country(117, "LS", "Lesotho"));
            countries.Add(new Country(118, "LR", "Liberia"));
            countries.Add(new Country(119, "LY", "Libya"));
            countries.Add(new Country(120, "LI", "Liechtenstein"));
            countries.Add(new Country(121, "LT", "Lithuania"));
            countries.Add(new Country(122, "LU", "Luxembourg"));
            countries.Add(new Country(123, "MO", "Macau"));
            countries.Add(new Country(124, "MK", "Macedonia"));
            countries.Add(new Country(125, "MG", "Madagascar"));
            countries.Add(new Country(126, "MW", "Malawi"));
            countries.Add(new Country(127, "MY", "Malaysia"));
            countries.Add(new Country(128, "MV", "Maldives"));
            countries.Add(new Country(129, "ML", "Mali"));
            countries.Add(new Country(130, "MT", "Malta"));
            countries.Add(new Country(131, "MH", "Marshall Islands"));
            countries.Add(new Country(132, "MQ", "Martinique"));
            countries.Add(new Country(133, "MR", "Mauritania"));
            countries.Add(new Country(134, "MU", "Mauritius"));
            countries.Add(new Country(135, "YT", "Mayotte"));
            countries.Add(new Country(136, "MX", "Mexico"));
            countries.Add(new Country(137, "FM", "Micronesia"));
            countries.Add(new Country(138, "MD", "Moldova"));
            countries.Add(new Country(139, "MC", "Monaco"));
            countries.Add(new Country(140, "MN", "Mongolia"));
            countries.Add(new Country(141, "MS", "Montserrat"));
            countries.Add(new Country(142, "MA", "Morocco"));
            countries.Add(new Country(143, "MZ", "Mozambique"));
            countries.Add(new Country(144, "MM", "Myanmar"));
            countries.Add(new Country(145, "NA", "Namibia"));
            countries.Add(new Country(146, "NR", "Nauru"));
            countries.Add(new Country(147, "NP", "Nepal"));
            countries.Add(new Country(148, "NL", "Netherlands"));
            countries.Add(new Country(149, "AN", "Netherlands Antilles"));
            countries.Add(new Country(150, "NC", "New Caledonia"));
            countries.Add(new Country(151, "NZ", "New Zealand"));
            countries.Add(new Country(152, "NI", "Nicaragua"));
            countries.Add(new Country(153, "NE", "Niger"));
            countries.Add(new Country(154, "NG", "Nigeria"));
            countries.Add(new Country(155, "NU", "Niue"));
            countries.Add(new Country(156, "NF", "Norfolk Island"));
            countries.Add(new Country(157, "KP", "North Korea"));
            countries.Add(new Country(158, "MP", "Northern Mariana Islands"));
            countries.Add(new Country(159, "NO", "Norway"));
            countries.Add(new Country(160, "OM", "Oman"));
            countries.Add(new Country(161, "PK", "Pakistan"));
            countries.Add(new Country(162, "PW", "Palau"));
            countries.Add(new Country(163, "PA", "Panama"));
            countries.Add(new Country(164, "PG", "Papua New Guinea"));
            countries.Add(new Country(165, "PY", "Paraguay"));
            countries.Add(new Country(166, "PE", "Peru"));
            countries.Add(new Country(167, "PH", "Philippines"));
            countries.Add(new Country(168, "PN", "Pitcairn"));
            countries.Add(new Country(169, "PL", "Poland"));
            countries.Add(new Country(170, "PT", "Portugal"));
            countries.Add(new Country(171, "PR", "Puerto Rico"));
            countries.Add(new Country(172, "QA", "Qatar"));
            countries.Add(new Country(173, "RE", "Reunion"));
            countries.Add(new Country(174, "RO", "Romania"));
            countries.Add(new Country(175, "RU", "Russian Federation"));
            countries.Add(new Country(176, "RW", "Rwanda"));
            countries.Add(new Country(177, "GS", "S. Georgia and S. Sandwich Islands"));
            countries.Add(new Country(178, "KN", "Saint Kitts and Nevis"));
            countries.Add(new Country(179, "LC", "Saint Lucia"));
            countries.Add(new Country(180, "VC", "Saint Vincent and The Grenadines"));
            countries.Add(new Country(181, "WS", "Samoa"));
            countries.Add(new Country(182, "SM", "San Marino"));
            countries.Add(new Country(183, "ST", "Sao Tome and Principe"));
            countries.Add(new Country(184, "SA", "Saudi Arabia"));
            countries.Add(new Country(185, "SN", "Senegal"));
            countries.Add(new Country(186, "SC", "Seychelles"));
            countries.Add(new Country(187, "SL", "Sierra Leone"));
            countries.Add(new Country(188, "SG", "Singapore"));
            countries.Add(new Country(189, "SK", "Slovakia"));
            countries.Add(new Country(190, "SI", "Slovenia"));
            countries.Add(new Country(191, "SB", "Solomon Islands"));
            countries.Add(new Country(192, "SO", "Somalia"));
            countries.Add(new Country(193, "ZA", "South Africa"));
            countries.Add(new Country(194, "KR", "South Korea"));
            countries.Add(new Country(195, "SU", "Soviet Union"));
            countries.Add(new Country(196, "ES", "Spain"));
            countries.Add(new Country(197, "LK", "Sri Lanka"));
            countries.Add(new Country(198, "SH", "St. Helena"));
            countries.Add(new Country(199, "PM", "St. Pierre and Miquelon"));
            countries.Add(new Country(200, "SD", "Sudan"));
            countries.Add(new Country(201, "SR", "Suriname"));
            countries.Add(new Country(202, "SJ", "Svalbard and Jan Mayen Islands"));
            countries.Add(new Country(203, "SZ", "Swaziland"));
            countries.Add(new Country(204, "SE", "Sweden"));
            countries.Add(new Country(205, "CH", "Switzerland"));
            countries.Add(new Country(206, "SY", "Syria"));
            countries.Add(new Country(207, "TW", "Taiwan"));
            countries.Add(new Country(208, "TJ", "Tajikistan"));
            countries.Add(new Country(209, "TZ", "Tanzania"));
            countries.Add(new Country(210, "TH", "Thailand"));
            countries.Add(new Country(211, "TG", "Togo"));
            countries.Add(new Country(212, "TK", "Tokelau"));
            countries.Add(new Country(213, "TO", "Tonga"));
            countries.Add(new Country(214, "TT", "Trinidad and Tobago"));
            countries.Add(new Country(215, "TN", "Tunisia"));
            countries.Add(new Country(216, "TR", "Turkey"));
            countries.Add(new Country(217, "TM", "Turkmenistan"));
            countries.Add(new Country(218, "TC", "Turks and Caicos Islands"));
            countries.Add(new Country(219, "TV", "Tuvalu"));
            countries.Add(new Country(220, "UG", "Uganda"));
            countries.Add(new Country(221, "UA", "Ukraine"));
            countries.Add(new Country(222, "AE", "United Arab Emirates"));
            countries.Add(new Country(223, "UK", "United Kingdom"));
            countries.Add(new Country(224, "US", "United States"));
            countries.Add(new Country(225, "UY", "Uruguay"));
            countries.Add(new Country(226, "UM", "US Minor Outlying Islands"));
            countries.Add(new Country(227, "VI", "US Virgin Islands"));
            countries.Add(new Country(228, "UZ", "Uzbekistan"));
            countries.Add(new Country(229, "VU", "Vanuatu"));
            countries.Add(new Country(230, "VE", "Venezuela"));
            countries.Add(new Country(231, "VN", "Viet Nam"));
            countries.Add(new Country(232, "WF", "Wallis and Futuna Islands"));
            countries.Add(new Country(233, "EH", "Western Sahara"));
            countries.Add(new Country(234, "YE", "Yemen"));
            countries.Add(new Country(235, "YU", "Yugoslavia"));
            countries.Add(new Country(236, "ZR", "Zaire"));
            countries.Add(new Country(237, "ZM", "Zambia"));
            countries.Add(new Country(238, "ZW", "Zimbabwe"));
            countries.Add(new Country(0, "", ""));


            return countries;
        }
        private static List<string> GetCounties()
        {
            List<string> counties = new List<string>();

            counties.Add("Bedfordshire");
            counties.Add("Berkshire");
            counties.Add("Buckinghamshire");
            counties.Add("Cambridgeshire");
            counties.Add("Cheshire");
            counties.Add("Cornwall");
            counties.Add("Cumberland");
            counties.Add("Derbyshire");
            counties.Add("Devon");
            counties.Add("Dorset");
            counties.Add("Durham");
            counties.Add("Essex");
            counties.Add("Gloucestershire");
            counties.Add("Hampshire");
            counties.Add("Herefordshire");
            counties.Add("Hertfordshire");
            counties.Add("Huntingdonshire");
            counties.Add("Kent");
            counties.Add("Lancashire");
            counties.Add("Leicestershire");
            counties.Add("Lincolnshire");
            counties.Add("Middlesex");
            counties.Add("Norfolk");
            counties.Add("Northamptonshire");
            counties.Add("Northumberland");
            counties.Add("Nottinghamshire");
            counties.Add("Oxfordshire");
            counties.Add("Rutland");
            counties.Add("Shropshire");
            counties.Add("Somerset");
            counties.Add("Staffordshire");
            counties.Add("Suffolk");
            counties.Add("Surrey");
            counties.Add("Sussex");
            counties.Add("Warwickshire");
            counties.Add("Westmorland");
            counties.Add("Wiltshire");
            counties.Add("Worcestershire");
            counties.Add("Yorkshire");
            counties.Add("Anglesey");
            counties.Add("Brecknockshire");
            counties.Add("Caernarfonshire");
            counties.Add("Carmarthenshire");
            counties.Add("Cardiganshire");
            counties.Add("Denbighshire");
            counties.Add("Flintshire");
            counties.Add("Glamorgan");
            counties.Add("Merioneth");
            counties.Add("Monmouthshire");
            counties.Add("Montgomeryshire");
            counties.Add("Pembrokeshire");
            counties.Add("Radnorshire");
            counties.Add("Aberdeenshire");
            counties.Add("Angus");
            counties.Add("Argyllshire");
            counties.Add("Ayrshire");
            counties.Add("Banffshire");
            counties.Add("Berwickshire");
            counties.Add("Buteshire");
            counties.Add("Cromartyshire");
            counties.Add("Caithness");
            counties.Add("Clackmannanshire");
            counties.Add("Dumfriesshire");
            counties.Add("Dunbartonshire");
            counties.Add("East");
            counties.Add("Fife");
            counties.Add("Inverness-shire");
            counties.Add("Kincardineshire");
            counties.Add("Kinross-shire");
            counties.Add("Kirkcudbrightshire");
            counties.Add("Lanarkshire");
            counties.Add("Midlothian");
            counties.Add("Morayshire");
            counties.Add("Nairnshire");
            counties.Add("Orkney");
            counties.Add("Peeblesshire");
            counties.Add("Perthshire");
            counties.Add("Renfrewshire");
            counties.Add("Ross-shire");
            counties.Add("Roxburghshire");
            counties.Add("Selkirkshire");
            counties.Add("Shetland");
            counties.Add("Stirlingshire");
            counties.Add("Sutherland");
            counties.Add("West");
            counties.Add("Wigtownshire");

            return counties;
        }

        public static bool KeyIsEditKey(Key key)
        {
            if (key != Key.Shift && key != Key.Alt && key != Key.CapsLock && key != Key.Ctrl && key != Key.Home)
                return true;
            return false;
        }

        public static ObservableCollection<ContactTransport> GetDummyData()
        {
            ObservableCollection<ContactTransport> dummyData = new ObservableCollection<ContactTransport>();

            ContactTransport ct1 = new ContactTransport();
            ct1.ContactId = 1;
            ct1.Surname = "One";
            ct1.AddressList = new ObservableCollection<ContactAddressTransport>();
            ct1.AddressList.Add(newContactAddress("House 1", "First Close", "Long Road", (int)eContactAddressType.Default, "Firstown", "UK", "", "HO1 8TY"));
            ct1.AddressList.Add(newContactAddress("Secondhouse", "Second Avenue", "", (int)eContactAddressType.MemoForeign, "Twotown", "", "Twoshire", "RT6 7QT"));
            dummyData.Add(ct1);

            ContactTransport ct2 = new ContactTransport();
            ct2.Surname = "Two";
            ct2.ContactId = 1;
            dummyData.Add(ct2);

            ContactTransport ct3 = new ContactTransport();
            ct3.Surname = "Three";
            ct3.ContactId = 1;
            ct3.AddressList = new ObservableCollection<ContactAddressTransport>();
            ct3.AddressList.Add(newContactAddress("House 3", "Street Three", "", (int)eContactAddressType.AdditonalForeign, "Threetown", "UK", "Threeshire", "PO3 3NE"));
            ct3.AddressList.Add(newContactAddress("House 3", "Street Three", "", (int)eContactAddressType.DefaultForeign, "Threetown", "US", "Threeshire", "PO3 3NE"));
            dummyData.Add(ct3);

            return dummyData;
        }

        public static ContactAddressTransport newContactAddress(
         string AddressLineAField,
         string AddressLineBField,
         string AddressLineCField,
         int AddressTypeField,
         string CityField,
         string CountryCodeField,
         string CountyField,
         string PostcodeField)
        {
            ContactAddressTransport ct = new ContactAddressTransport();
            ct.ContactAddressId = Guid.NewGuid();
            ct.AddressLineA = AddressLineAField;
            ct.AddressLineB = AddressLineBField;
            ct.AddressLineC = AddressLineCField;
            ct.AddressType = AddressTypeField;
            ct.City = CityField;
            ct.CountryCode = CountryCodeField;
            ct.County = CountyField;
            ct.Postcode = PostcodeField;
            return ct;
        }

    }

    public class Country
    {
        public int CountryId { get; set; }
        public string Code { get; set; }
        public string Name { get; set; }

        public Country(int countryId, string code, string name)
        {
            this.CountryId = countryId;
            this.Code = code;
            this.Name = name;
        }
    }

    public class ContactAddressType
    {
        private int _typeId;
        public int TypeId
        { get { return _typeId; } }

        private string _title;
        public string Title
        { get { return _title; } }

        private string _code;
        public string Code
        { get { return _code; } }

        private bool _isForeign;
        public bool IsForeign
        { get { return _isForeign; } }

        public ContactAddressType(int typeId, string title, string code, bool isForeign)
        {
            this._typeId = typeId;
            this._title = title;
            this._code = code;
            this._isForeign = isForeign;
        }
    }

    [Flags]
    public enum eContactAddressType
    {
        NotSet = 0,
        Default = 1,
        Memo = 2,
        Additonal = 4,
        Foreign = 16,
        DefaultForeign = Default + Foreign,
        MemoForeign = Memo + Foreign,
        AdditonalForeign = Additonal + Foreign
    }

}
